Page({
    data: {
      tabList: [
        { name: '酒店', image: '/assets/index/酒店.png', url: '/function/hotel/hotel' },
        { name: '机票', image: '/assets/index/国际机票.png', url: '/function/plane/plane' },
        { name: '火车票', image: '/assets/index/火车票.png', url: '/function/train/train' },
        { name: '旅游', image: '/assets/index/旅游.png', url: '/pages/play/play' }, // 修改路径
      ],
      activeTab: 0, // 当前选中的标签
      imageUrls: [], // 轮播图图片
      leftItems: [], // 左侧数据
      rightItems: [], // 右侧数据
      page: 1, // 当前页码
      pageSize: 3, // 每页数据量
      isRefreshing: false, // 是否正在刷新
      isLoadingMore: false, // 是否正在加载更多
    },
  
    onLoad() {
      this.loadImages();
      this.loadData();
    },
  
    // 加载轮播图图片
    loadImages() {
      setTimeout(() => {
        const imageUrls = [
          'https://img1.qunarzz.com/travel/poi/1808/b4/b2b51ea3aed42a37.jpg',
          'https://pic1.zhimg.com/v2-0cc7136788db7ce363ef8c76d2d7be28_r.jpg',
          'https://th.bing.com/th/id/R.052a8bc533e6f5cbfea9354561e32bf1?rik=azM%2bwPpPauar5g&riu=http%3a%2f%2fseopic.699pic.com%2fphoto%2f50042%2f9675.jpg_wh1200.jpg&ehk=Vv0qcKv366byPGKs5%2beC8KaVbnhfYsaBbStjap9UV9E%3d&risl=&pid=ImgRaw&r=0',
        ];
        this.setData({ imageUrls });
      }, 1000);
    },
  
    // 点击标签跳转到对应页面
    goToPage(e) {
      const url = e.currentTarget.dataset.url;
      const index = e.currentTarget.dataset.index;
  
      // 保存当前激活的标签索引到本地存储
      wx.setStorageSync('activeTab', index);
  
      // 判断是否是 Tab 页面
      if (url.startsWith('/pages')) {
        wx.navigateTo({
          url: url,
        });
      } else {
        wx.switchTab({
          url: url,
        });
      }
    },
  
    // 加载数据
    loadData() {
      const { page, pageSize } = this.data;
      const offset = (page - 1) * pageSize;
  
      // 请求左侧数据
      wx.request({
        url: 'https://7696-218-88-164-24.ngrok-free.app/images',
        method: 'GET',
        header: {
          'ngrok-skip-browser-warning': 'true'
        },
        data: {
          page,
          pageSize,
        },
        success: (res) => {
          const items = res.data.items || [];
          this.setData({
            leftItems: page === 1 ? items : [...this.data.leftItems, ...items],
          });
        },
        fail: (err) => {
          console.error('请求左侧数据失败', err);
          this.setData({
            leftItems: [],
          });
        },
      });
  
      // 请求右侧数据
      wx.request({
        url: 'https://7696-218-88-164-24.ngrok-free.app/user',
        method: 'GET',
        header: {
          'ngrok-skip-browser-warning': 'true'
        },
        data: {
          page,
          pageSize,
        },
        success: (res) => {
          const items = res.data.items || [];
          this.setData({
            rightItems: page === 1 ? items : [...this.data.rightItems, ...items],
          });
        },
        fail: (err) => {
          console.error('请求右侧数据失败', err);
          this.setData({
            rightItems: [],
          });
        },
        complete: () => {
          this.setData({
            isRefreshing: false,
            isLoadingMore: false,
          });
        },
      });
    },
  });